package Demo1;

/**
 * 多态 重写
 */
class Animal {
    String name;
    public Animal(String name) {
        this.name = name;
    }

    public void voice() {
        System.out.println(name + "在叫~");
    }
}

class Dog extends Animal {
    public Dog(String name) {
        super(name);
    }

    @Override
    public void voice() {
        System.out.println(name + "在汪汪汪！");
    }
}

class Cat extends Animal {
    public Cat(String name) {
        super(name);
    }

    @Override
    public void voice() {
        System.out.println(name + "在喵喵喵~");
    }
}
public class test1 {
    public static void voice(Animal animal) {
        animal.voice();
    }
    public static void main(String[] args) {
        Animal animal = new Animal("小动物");
        Dog dog = new Dog("狗子");
        Cat cat = new Cat("咪子");
        voice(animal);
        voice(dog);
        voice(cat);
    }
}
